package com.desmart.renjiao.main.addresslist;

import com.desmart.renjiao.bean.CheckMonthResult;
import com.desmart.renjiao.bean.GetOrgainzationResult;
import com.desmart.renjiao.bean.WorkDay;
import com.desmart.renjiao.xmlparase.ResultXmlUtils;
import com.google.gson.Gson;
import com.lemon.library.net.rx.RxObservableListener;

import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.util.List;

import okhttp3.MediaType;
import okhttp3.RequestBody;
import okhttp3.ResponseBody;

public class AddresslistP extends Addresslist.AddresslistP{

    @Override
    void getOrgainzation() {

        String xml = "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:ser=\"http://services.destram.cn.com/\">\n" +
                "<soapenv:Header/>\n" +
                "<soapenv:Body>\n" +
                "<ser:SeacheOrganization>\n" +
                "<!--Optional:-->\n" +
                "<arg0>#</arg0>\n" +
                "</ser:SeacheOrganization>\n" +
                "</soapenv:Body>\n" +
                "</soapenv:Envelope>";


        RequestBody body = RequestBody.create(MediaType.parse("application/json; charset=utf-8"), xml);
        getRxManager().addObserver(mModel.getOrganizaiton(body), new RxObservableListener<ResponseBody>(mView) {
            @Override
            public void onNext(ResponseBody responseBody) {
                super.onNext(responseBody);
                String ss = null;

                try {
                    ss = responseBody.string();
                    InputStream inputStream = new ByteArrayInputStream(ss.getBytes("UTF-8"));
                    String result = ResultXmlUtils.readXML(inputStream);
                    GetOrgainzationResult getOrgainzationResult = new Gson().fromJson(result, GetOrgainzationResult.class);
                    if ("200".equals(getOrgainzationResult.getCode())){
                        mView.onSuccessGetOrgainzaiton(getOrgainzationResult.getCompany());
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });

    }


}
